var n;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PlayerDataMgr = undefined;
var r;
var DataManager = require("AA_DataManager");
var EventManager = require("AA_EventManager");
var TipsManager = require("AA_TipsManager");
var CommonUtils = require("AA_CommonUtils");
var TimeUtils = require("AA_TimeUtils");
var Const_Common = require("AA_Const_Common");
var RedPointControl = require("AA_RedPointControl");
var Excel = require("AA_Excel");
var GameDataManager = require("AA_GameDataManager");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var EvenType = require("AA_EvenType");
!function (e) {
  e.global = "global";
}(r || (r = {}));
var y = function () {
  this.power = 30;
  this.maxPower = 30;
  this.gold = 0;
  this.diamond = 0;
  this.equipSaveData = {};
  this.dressUpArray = [0, 0, 0, 0, 0, 0, -1, -1];
  this.saveCount = 0;
  this.nextResetTime = 0;
  this.lastAddPowerTime = 0;
  this.addPowerTime = 0;
  this.videoAddPowerTime = 0;
  this.guideMap = {};
  this.guideSendIndex = 0;
  this.wujincount = 3;
  this.wujintime = 0;
  this.saodangcount = 3;
  this.saodangtime = 0;
  this.qiandaocount = 0;
  this.isqiandaocode = 1;
  this.qiandaotime = 0;
  this.duihuanjilu = {};
};
var v = function () {
  this.level = 1;
  this.isUnLock = false;
  this.fragments = 0;
};
var b = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t._secret_key = "playerData";
    t.globalData = new y();
    t.WHITE_NAME_NO_VIDEO = false;
    return t;
  }
  __extends(t, e);
  Object.defineProperty(t.prototype, "chapter", {
    get: function () {
      return GameDataManager.GameDataMgr.getNowMaxLevel() || 1;
    },
    enumerable: false,
    configurable: true
  });
  t.prototype.GetGuideIndexByTaskName = function (e) {
    this.globalData.guideMap[e] || (this.globalData.guideMap[e] = 0);
    return this.globalData.guideMap[e];
  };
  t.prototype.SetGuideIndex = function (e, t) {
    this.globalData.guideMap[e] || (this.globalData.guideMap[e] = 0);
    if (t > this.globalData.guideMap[e]) {
      this.globalData.guideMap[e] = t;
      this.SaveGlobalData();
      var o = e;
      var n = "" + t;
      switch (e) {
        case Const_Common.GuideName.战斗背包:
          o = "战斗背包";
          n = ["引导初始1", "引导拖动水果2", "引导刷新按钮3", "引导合成4", "引导开战6", "引导词条7", "引导词条7完结", "引导格子8", "引导其他水果9", "引导结束10", "引导完结"][t];
          break;
        case Const_Common.GuideName.仓库升级:
          o = "仓库升级";
          n = ["给固定奖励1", "引导点击仓库水果2", "引导点击升级3", "引导战斗4", "引导完结"][t];
          break;
        case Const_Common.GuideName.水果上阵:
          o = "水果上阵";
          n = ["引导对话", "选择水果", "引导穿戴", "引导完结"][t];
      }
      var i = o + "_" + n;
      if (e == Const_Common.GuideName.战斗背包 && t <= this.globalData.guideSendIndex) {
        return;
      }
      this.globalData.guideSendIndex = t;
      CommonUtils.default.SendPoint(Const_Common.SendPointType.新手引导, i);
    }
  };
  t.prototype.GMSetGuideIndex = function (e, t) {
    this.globalData.guideMap[e] = t;
    this.SaveGlobalData();
  };
  t.prototype.init = function (e) {
    undefined === e && (e = null);
    console.log("远程数据", e);
    this.globalData = new y();
    var t = this.getNowData(r.global, e);
    this.globalData = __assign(__assign({}, this.globalData), t);
    this.StartCheckEquip();
    this.CheckIsTimeToReset();
    this.OtherCheck();
    t || this.PlayerFirstTime();
  };
  t.prototype.saveDuiHuanJiLu = function (e) {
    this.globalData.duihuanjilu[e] = "ok";
    this.SaveGlobalData();
  };
  t.prototype.isDuiHuan = function (e) {
    return this.globalData.duihuanjilu[e];
  };
  t.prototype.getNowData = function (e, t) {
    var o = null;
    if (t && (o = t[e])) {
      this.updateDataMap(e, o);
    } else {
      o = this._load(e);
    }
    return o;
  };
  t.prototype.OtherCheck = function () {
    var e = Excel.Excel.wareHouseControl(1).unLockArray;
    for (var t = 0; t < e.length; t++) {
      if (t > this.globalData.dressUpArray.length) {
        this.globalData.dressUpArray.push(-1);
      } else if (this.chapter < e[t]) {
        this.globalData.dressUpArray[t] = -1;
      } else {
        this.chapter >= e[t] && -1 == this.globalData.dressUpArray[t] && (this.globalData.dressUpArray[t] = 0);
      }
    }
  };
  t.prototype.CheckIsTimeToReset = function () {
    var e = new Date();
    var t = e.getTime();
    if (!this.globalData.nextResetTime || t >= this.globalData.nextResetTime) {
      e.setHours(24, 0, 0, 0);
      this.globalData.nextResetTime = e.getTime();
      this.ResetAllByTime();
    }
  };
  t.prototype.ResetAllByTime = function () {
    this.globalData.addPowerTime = 0;
    this.globalData.videoAddPowerTime = 0;
    this.SaveGlobalData();
  };
  t.prototype.SaveGlobalData = function () {
    this._save(r.global, this.globalData);
  };
  t.prototype.AddPower = function (e) {
    this.globalData.power += e;
    this.ChangeRich();
  };
  t.prototype.SubPower = function (e) {
    if (this.globalData.power < e) {
      TipsManager.TipMgr.showToast("体力不足");
      return false;
    } else {
      this.globalData.power >= this.globalData.maxPower && this.globalData.power - e < this.globalData.maxPower && (this.globalData.lastAddPowerTime = new Date().getTime());
      this.globalData.power -= e;
      this.ChangeRich();
      return true;
    }
  };
  t.prototype.AddGold = function (e) {
    this.globalData.gold += e;
    this.ChangeRich();
  };
  t.prototype.SubGold = function (e) {
    if (this.globalData.gold < e) {
      TipsManager.TipMgr.showToast("金币不足");
      return false;
    } else {
      this.globalData.gold -= e;
      this.ChangeRich();
      return true;
    }
  };
  t.prototype.AddDiamond = function (e) {
    this.globalData.diamond += e;
    this.ChangeRich();
  };
  t.prototype.SubDiamond = function (e) {
    if (this.globalData.diamond < e) {
      TipsManager.TipMgr.showToast("钻石不足");
      return false;
    } else {
      this.globalData.diamond -= e;
      this.ChangeRich();
      return true;
    }
  };
  t.prototype.ChangeRich = function () {
    this.SaveGlobalData();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Hall_ResetRich);
  };
  t.prototype.PlayerFirstTime = function () {
    var e = this;
    Excel.Excel.shuiguo_all.forEach(function (t) {
      -1 != t.isShow && t.unLock <= e.chapter && e.AddDressUpEquip(t.id);
    });
  };
  t.prototype.StartCheckEquip = function () {
    var e = this;
    var t = false;
    Excel.Excel.shuiguo_all.forEach(function (o) {
      if (!e.globalData.equipSaveData[o.id]) {
        e.globalData.equipSaveData[o.id] = new v();
        t = true;
      }
      e.globalData.equipSaveData[o.id].isUnLock = e.chapter >= o.unLock;
    });
    t && this.SaveGlobalData();
  };
  t.prototype.GameWinCheckUnlock = function () {
    var e = this;
    var t = [];
    var o = false;
    var n = this.chapter;
    Excel.Excel.shuiguo_all.forEach(function (i) {
      if (!e.globalData.equipSaveData[i.id].isUnLock && n >= i.unLock) {
        e.globalData.equipSaveData[i.id].isUnLock = true;
        o = true;
        t.push(i.id);
      }
    });
    if (o) {
      this.SaveGlobalData();
      this.OtherCheck();
    }
    return t;
  };
  Object.defineProperty(t.prototype, "dressUpArray", {
    get: function () {
      return this.globalData.dressUpArray;
    },
    enumerable: false,
    configurable: true
  });
  t.prototype.HallGetEquipIsDressUp = function (e) {
    return !!Excel.Excel.shuiguo(e) && -1 != this.dressUpArray.indexOf(e);
  };
  t.prototype.GetEquipIsDressUp = function (e) {
    var t = Excel.Excel.shuiguo(e);
    return !t || -1 != this.dressUpArray.indexOf(e) || -1 == t.isShow;
  };
  t.prototype.AddDressUpEquip = function (e, t) {
    undefined === t && (t = -1);
    if (-1 == t) {
      for (var o = 0; o < this.globalData.dressUpArray.length; o++) {
        if (0 == this.globalData.dressUpArray[o]) {
          t = o;
          break;
        }
      }
      if (-1 == t) {
        return;
      }
    }
    this.globalData.dressUpArray[t] = e;
    this.SaveGlobalData();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.MainRedPointChange, RedPointControl.RedPointType.upEquip);
  };
  t.prototype.RemoveDressUpEquip = function (e, t) {
    undefined === t && (t = -1);
    if (-1 == t) {
      for (var o = 0; o < this.globalData.dressUpArray.length; o++) {
        if (this.globalData.dressUpArray[o] == e) {
          t = o;
          break;
        }
      }
      if (-1 == t) {
        return;
      }
    }
    this.globalData.dressUpArray[t] = 0;
    this.SaveGlobalData();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.MainRedPointChange, RedPointControl.RedPointType.upEquip);
  };
  t.prototype.AddEquipLevel = function (e) {
    if (this.globalData.equipSaveData[e] && this.globalData.equipSaveData[e].isUnLock) {
      this.globalData.equipSaveData[e].level++;
      this.SaveGlobalData();
    }
  };
  t.prototype.AddEquipFragments = function (e, t) {
    this.globalData.equipSaveData[e].fragments += t;
    this.SaveGlobalData();
    RedPointControl.RedPointCtrl.GetRedPointByType(RedPointControl.RedPointType.upEquip) && EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.MainRedPointChange, RedPointControl.RedPointType.upEquip);
  };
  t.prototype.UseEquipFragments = function (e, t) {
    if (this.globalData.equipSaveData[e].fragments < t) {
      TipsManager.TipMgr.showToast("碎片不足");
      return false;
    } else {
      this.globalData.equipSaveData[e].fragments -= t;
      this.SaveGlobalData();
      return true;
    }
  };
  t.prototype.GetEquipDataById = function (e) {
    return this.globalData.equipSaveData[e];
  };
  t.prototype.getWuJinCount = function () {
    this.resetWuJinCount();
    return this.globalData.wujincount;
  };
  t.prototype.subWuJinCount = function (e) {
    this.globalData.wujincount -= e;
    this.SaveGlobalData();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_TIAOZHAN_COUNT);
  };
  t.prototype.resetWuJinCount = function (e) {
    undefined === e && (e = false);
    if (0 == this.globalData.wujintime || e) {
      GameDataManager.GameDataMgr.cleanTiaoZhanLevel(1);
      this.globalData.wujincount = GameGlobalVariable.GameGlobalVariable.wujinmeirifreecount;
      this.globalData.wujintime = new Date().getTime();
      this.SaveGlobalData();
    } else if (!TimeUtils.default.isSameDay(this.globalData.wujintime, new Date().getTime())) {
      this.globalData.wujincount = GameGlobalVariable.GameGlobalVariable.wujinmeirifreecount;
      this.globalData.wujintime = new Date().getTime();
      GameDataManager.GameDataMgr.cleanTiaoZhanLevel(1);
      this.SaveGlobalData();
    }
  };
  t.prototype.getSaoDangCount = function () {
    this.resetSaoDangCount();
    return this.globalData.saodangcount;
  };
  t.prototype.subSaoDangCount = function (e) {
    this.globalData.saodangcount -= e;
    this.SaveGlobalData();
  };
  t.prototype.resetSaoDangCount = function () {
    if (0 == this.globalData.saodangtime) {
      this.globalData.saodangcount = GameGlobalVariable.GameGlobalVariable.meirimianfeicount;
      this.globalData.saodangtime = new Date().getTime();
      this.SaveGlobalData();
    } else if (!TimeUtils.default.isSameDay(this.globalData.saodangtime, new Date().getTime())) {
      this.globalData.saodangcount = GameGlobalVariable.GameGlobalVariable.meirimianfeicount;
      this.globalData.saodangtime = new Date().getTime();
      this.SaveGlobalData();
    }
  };
  t.prototype.getQianDaoCount = function () {
    return this.globalData.qiandaocount;
  };
  t.prototype.subQianDaoCount = function (e) {
    this.globalData.qiandaocount += e;
    this.globalData.qiandaocount > Excel.Excel.shuiguoqiandao_all.size && (this.globalData.qiandaocount = 0);
    this.SaveGlobalData();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_QianDao_COUNT);
  };
  t.prototype.setQianDaoState = function () {
    this.globalData.isqiandaocode = 2;
    this.subQianDaoCount(1);
    this.globalData.qiandaotime = new Date().getTime();
    this.SaveGlobalData();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.HOME_QIANDAO_UPDATE);
  };
  t.prototype.resetData = function () {
    this._clear();
  };
  t.prototype.resetQianDaoCount = function () {
    if (0 == this.globalData.qiandaotime) {
      this.globalData.isqiandaocode = 1;
      this.SaveGlobalData();
    } else if (!TimeUtils.default.isSameDay(this.globalData.qiandaotime, this.getServerTime().getTime())) {
      this.globalData.isqiandaocode = 1;
      this.globalData.qiandaocount >= 9 && (this.globalData.qiandaocount = 0);
      this.SaveGlobalData();
    }
  };
  t.prototype.getServerTime = function () {
    return new Date();
  };
  return t;
}(DataManager.default);
exports.PlayerDataMgr = b.getInstance();